﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;

namespace CYP.IISMonitor.Utility.SMS
{
    /// <summary>
    /// 创世漫道
    /// </summary>
    public class ManDaoPath : IMsg
    {
        public string SendMsg(string mobile, string contents, MSGTYPE msgType)
        {
            try
            {
                string result = string.Empty;
                string returnVal = string.Empty;
                MsgExtension extension = null;
                using (cn.entinfo.sdk2.WebService websms = new cn.entinfo.sdk2.WebService())
                {
                    websms.Timeout = 5000;
                    string sn = "xxxxxx";
                    string pwd = "xxxxxx";
                    string md5Str = FormsAuthentication.HashPasswordForStoringInConfigFile(sn + pwd, "md5");
                    extension = new MsgExtension().Init(msgType);//初始化短信类型
                    returnVal = websms.mt("xxxxxx", md5Str, mobile, contents, extension.ExtMd, "", "");//成功以后返回值是流水号 051105283065061356
                }
                if (returnVal.StartsWith("-") || returnVal == "1")
                    result = "发送失败" + returnVal;
                else
                    result = "1";
                SMSLogWriter.Info("[创世漫道]返回信息：" + returnVal);
                int length = 1;
                if (mobile.IndexOf(',') > 0)
                    length = mobile.Split(',').Length;
                //DateLog.insertSMSby2(orid, aucid, mobile, contents, result, (int)msgType, extension.ExtMd); //写入数据库日志
                SMSLogWriter.Info("[创世漫道]发送成功：" + length + "条");
                return "发送成功" + length + "条(重复手机号只发一条)";
            }
            catch (Exception ee)
            {
                SMSLogWriter.Info("通道二底层异常，原因：" + ee.ToString());
                return "-1";// "通道二发送失败";
            }
        }
    }
}
